<?php

namespace app\common\model\xiluhouse;

use think\Model;
use traits\model\SoftDelete;

class Advert extends Base
{

    use SoftDelete;



    // 表名
    protected $name = 'xiluhouse_advert';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'min_image_text',
        'image_text',
        'image_text2',
        'position_text',
        'jump_type_text',
        'goto_type_text',
        'status_text'
    ];


    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function getMinImageTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['min_image']) ? $data['min_image'] : '');
        return cdnurl($value,true);
    }
    public function getPositionList()
    {
        return ['1' => __('Position 1'), '2' => __('Position 2'), '3' => __('Position 3'), '4' => __('Position 4'), '5' => __('Position 5')];
    }

    public function getJumpTypeList()
    {
        return ['1' => __('Jump_type 1'), '2' => __('Jump_type 2'), '3' => __('Jump_type 3'), '4' => __('Jump_type 4'), '5' => __('Jump_type 5'), '6' => __('Jump_type 6'), '7' => __('Jump_type 7'), '8' => __('Jump_type 8'), '9' => __('Jump_type 9'), '10' => __('Jump_type 10'), '11' => __('Jump_type 11'), '12' => __('Jump_type 12'), '13' => __('Jump_type 13')];
    }

    public function getGotoTypeList()
    {
        return ['1' => __('Goto_type 1'), '2' => __('Goto_type 2'), '3' => __('Goto_type 3'), '4' => __('Goto_type 4'), '5' => __('Goto_type 5')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Status normal'), 'hidden' => __('Status hidden')];
    }


    public function getPositionTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['position']) ? $data['position'] : '');
        $list = $this->getPositionList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getJumpTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['jump_type']) ? $data['jump_type'] : '');
        $list = $this->getJumpTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGotoTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['goto_type']) ? $data['goto_type'] : '');
        $list = $this->getGotoTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function insidepages()
    {
        return $this->belongsTo('InsidePages', 'inside_pages_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
